using System;
using NUnit.Framework ;
using Crawler ;

namespace Crawler.Tests
{
	/// <summary>
	/// Summary description for TestPathExtractor.
	/// </summary>
	[TestFixture]
	public class TestPathExtractor
	{
		ICentralFactory factory ;
		IPathExtractor pathExtractor;
		IKey key;
	
		[SetUp]
		public void Initialize()
		{
			factory = CentralFactory.centralFactory ;
			factory.Add(@"http://www.yahoo.com/main/") ;
			pathExtractor = new PathExtractor(factory);
		}

		[Test]
		public void TestExtractRelativePathFromUrl()
		{
		   	Assertion.AssertEquals("",pathExtractor.ExtractRelativePathFromUrl(new Key(@"http://www.yahoo.com/")))  ;
			Assertion.AssertEquals("",pathExtractor.ExtractRelativePathFromUrl(new Key(@"http://www.yahoo.com/main/"))) ;
			Assertion.AssertEquals("images",pathExtractor.ExtractRelativePathFromUrl(new Key(@"http://www.yahoo.com/main/images"))) ;
			Assertion.AssertEquals("videos/bryan adams",pathExtractor.ExtractRelativePathFromUrl(new Key(@"http://www.yahoo.com/main/videos/bryan adams"))) ;
			Assertion.AssertEquals("videos/bryan adams/18 till i die.html",pathExtractor.ExtractRelativePathFromUrl(new Key(@"http://www.yahoo.com/main/videos/bryan adams/18 till i die.html"))) ;
			Assertion.AssertEquals("german/abinitio/chap1-2.html#top",pathExtractor.ExtractRelativePathFromUrl(new Key(@"http://www.exeter.ac.uk/german/abinitio/chap1-2.html#top"))) ;
		}		

		[Test]
		public void TestExtractAbsolutePathFromUrl() {
			factory.Add(new ResourcePath("c:/temp")) ;
			string baseDirPath = factory.GetPath().ToString();
			Assertion.AssertEquals("c:/temp/tc/output/btree.exe",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"file:///m:/tc/output/btree.exe")));
			Assertion.AssertEquals(@"c:/temp/testdata/3.2 - Planning An Approach.htm",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"file:///c:/testdata/3.2 - Planning An Approach.htm")));
			Assertion.AssertEquals("c:/temp/",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"http://www.yahoo.com/")));
			Assertion.AssertEquals("c:/temp/",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"http://www.yahoo.com/main/"))) ;
			Assertion.AssertEquals("c:/temp/images",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"http://www.yahoo.com/main/images"))) ;
			Assertion.AssertEquals("c:/temp/videos/bryan adams",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"http://www.yahoo.com/main/videos/bryan adams"))) ;
			Assertion.AssertEquals("c:/temp/videos/bryan adams/18 till i die.html",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"http://www.yahoo.com/main/videos/bryan adams/18 till i die.html"))) ;
			Assertion.AssertEquals("c:/temp/german/abinitio/chap1-2.html#top",pathExtractor.ExtractAbsolutePathFromUrl(new Key(@"http://www.exeter.ac.uk/german/abinitio/chap1-2.html#top"))) ;
		}		

	}
}
